<?php
/**
 * --------------------------------------------------------------
 * 全局验证码类
 * --------------------------------------------------------------
 * Light Year Doc
 * @author yinq<3331653644@qq.com>
 * --------------------------------------------------------------
 */
namespace app\api\controller;

use app\common\controller\Base;
use think\captcha\Captcha;

class Checkcode extends Base
{
    /**
     * 获取验证码
     */
    public function getVerify()
    {
        $captcha = [];
        // 验证码长度
        $codelen = $this->request->param('length', 4);
        if ($codelen) {
            if ($codelen > 8 || $codelen < 2) {
                $codelen = 4;
            }
            $captcha['length'] = $codelen;
        }
        // 验证码字体大小
        $fontSize = $this->request->param('fontSize', 15);
        if ($fontSize) {
            $captcha['fontSize'] = $fontSize;
        }
        // 验证码图片宽度
        $width = $this->request->param('imageW', 40);
        if ($width) {
            $captcha['imageW'] = $width;
        }
        // 验证码图片高度
        $height = $this->request->param('imageH', 110);
        if ($height) {
            $captcha['imageH'] = $height;
        }
        $captcha = new Captcha($captcha);

        return $captcha->entry();
    }
}